/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Reportes;

import clases.abmBovino;
import clases.conexion;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.swing.JRViewer;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Ele
 */
public class MetodosImpresion {
    /**
     * Dimesiones de la patalla
     */
    private Toolkit tk = Toolkit.getDefaultToolkit();
    private Dimension screenSize = tk.getScreenSize();

    /**
     * @param args the command line arguments
     */
    public void ReporteAnimales() throws ClassNotFoundException, SQLException {
        Conectar();
        try {
            JDialog viewer = new JDialog(new JFrame(), "Vista previa del reporte", true);

            viewer.setSize(screenSize.width, screenSize.height);
            viewer.setLocationRelativeTo(null);

            //Class.forName("org.gjt.mm.mysql.Driver");
            //Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "root");
            JasperReport jasperReport = (JasperReport) JRLoader.loadObject(this.getClass().getResource("ListadoAnimales.jasper"));

            Map parametros = new HashMap();
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parametros, db.getMyConnection());

            //JasperViewer jviewer = new JasperViewer(jasperPrint, false);
            //jviewer.setTitle("LISTADO DE ANIMALES");
            //jviewer.setVisible(true);
            JRViewer jrv = new JRViewer(jasperPrint);
            viewer.getContentPane().add(jrv);
            viewer.show();

        } catch (JRException e) {
            e.printStackTrace();
        }
    }

    
    public void ReporteCantidadAnimales() throws ClassNotFoundException, SQLException {
        Conectar();
        try {
            JDialog viewer = new JDialog(new JFrame(), "Vista previa del reporte", true);

            viewer.setSize(screenSize.width, screenSize.height);
            viewer.setLocationRelativeTo(null);

            //Class.forName("org.gjt.mm.mysql.Driver");
            //Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost/mydb", "root", "root");
            JasperReport jasperReport = (JasperReport) JRLoader.loadObject(this.getClass().getResource("EstadoAnimal.jasper"));
            int suma= new abmBovino().CantidadBovino();
            Map parametros = new HashMap();
            parametros.put("suma",suma);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parametros, db.getMyConnection());

            //JasperViewer jviewer = new JasperViewer(jasperPrint, false);
            //jviewer.setTitle("LISTADO DE ANIMALES");
            //jviewer.setVisible(true);
            JRViewer jrv = new JRViewer(jasperPrint);
            viewer.getContentPane().add(jrv);
            viewer.show();

        } catch (JRException e) {
            e.printStackTrace();
        }
    }
    
    
 
    private conexion db;
    private Statement stmt;

    public void Conectar() {
        try {
            db = new conexion();      //instancia de la clase conexion.java
            db.init();
            Connection conn = db.getMyConnection();
            stmt = conn.createStatement();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Problemas al concetarse a la Base de Datos", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}